import api from './index'

export default {
  // 获取某员工的培训经历列表
  getAll(employeeId) {
    return api.get(`/api/employees/${employeeId}/training-experience`)
  },
  // 获取某员工的单条培训经历
  getOne(employeeId, id) {
    return api.get(`/api/employees/${employeeId}/training-experience/${id}`)
  },
  // 新增培训经历
  add(employeeId, data) {
    return api.post(`/api/employees/${employeeId}/training-experience`, data)
  },
  // 编辑培训经历
  update(employeeId, id, data) {
    return api.put(`/api/employees/${employeeId}/training-experience/${id}`, data)
  },
  // 删除培训经历
  remove(employeeId, id) {
    return api.delete(`/api/employees/${employeeId}/training-experience/${id}`)
  },
  // 获取培训经历附件列表
  getAttachments(trainingId) {
    return api.get(`/api/training-attachments/${trainingId}`)
  },
  // 上传附件
  addAttachment(trainingId, file, description = '', uploader = '系统') {
    const formData = new FormData()
    formData.append('file', file)
    formData.append('description', description)
    formData.append('uploader', uploader)
    return api.post(`/api/training-attachments/${trainingId}`, formData, {
      headers: { 'Content-Type': 'multipart/form-data' }
    })
  },
  // 删除附件
  deleteAttachment(trainingId, attachmentId) {
    return api.delete(`/api/training-attachments/${trainingId}/${attachmentId}`)
  },
  // 下载附件
  download(attachmentId) {
    return api.get(`/api/attachments/download/${attachmentId}`, { responseType: 'blob' })
  },
  // 获取附件预览URL
  getPreviewUrl(attachmentId) {
    return `/api/attachments/download/${attachmentId}`
  }
} 